{extend name="public:base" /}
{block name="style"}
<style>
    .positionForm {
        padding: 10px;
    }
    .h30{
        height: 30px;
        line-height: 30px;
    }
</style>
{/block}
{block name="main-content"}
<div class="page-content">

    <div class="row">
        <div id="positionFormDiv" class="col-xs-4">
            <form class="positionForm" action="{:url('admin/position/set')}" method="post">
                <div class="form-group">
                    <label for="name">推荐位名称</label>
                    <input type="text" class="form-control" id="name" name="name" value="{$position.name}" required placeholder="推荐位名称">
                </div>

                <div class="form-group">
                    <label for="status">状态</label>
                    <select class="form-control" id="status" name="status">
                        {foreach  name="status" id="vo" key="key"}
                        <option value="{$key}" {if condition="isset($position) && $position->getData('status') == $key"}selected{/if}>{$vo}</option>
                        {/foreach}
                    </select>
                </div>
                <div class="form-group">
                    <label for="description">描述</label>
                    <input type="text" class="form-control" id="description" name="description" value="{$position.description}" required placeholder="描述">
                </div>
                <input type="hidden" id="id" name="id" value="{$position.id}">
                <button type="submit" class="btn btn-primary">保存</button>
            </form>
        </div>
    </div><!-- /.row -->
</div><!-- /.page-content -->
{/block}

{block name="scripts"}
<script type="text/javascript">
    /* 添加分类 */
    $(function () {
        $('.positionForm').ajaxForm({
            success: positionForm, // 这是提交后的方法
            dataType: 'json'
        });
    });

    //添加权限
    function positionForm(data) {
        if (data.code == 1) {
            $(':input', '.positionForm')
                    .not(':button, :submit, :reset, :hidden')
                    .val('')
                    .removeAttr('checked')
                    .removeAttr('selected');
            layer.msg(data.msg, {icon: 6});
            if (data.url) {
                window.location.href = data.url;
            }
        } else {
            layer.alert(data.msg, {icon: 5});
        }
    }

    $(document).ready(function () {
        var tree = [];
        $('.action-buttons a').on('mousedown', function(e){
            var id = $(this).data('id');

            console.log(tree[id]);

            if (typeof tree[id] != 'undefined' && tree[id]) {
                $('.treeSub-'+id).addClass('hide');
                $(this).find('.fa').addClass('fa-angle-double-down');
                $(this).find('.fa').removeClass('fa-angle-double-up');
                tree[id] = false;
            } else {
                $('.treeSub-'+id).removeClass('hide');
                $(this).find('.fa').addClass('fa-angle-double-up');
                $(this).find('.fa').removeClass('fa-angle-double-down');
                tree[id] = true;
            }

        });
    })



</script>
{/block}